Ext.define('Lms.rms.HardwareChangePanel',{
	extend : 'Ext.grid.Panel',
	initComponent : function(){
		Ext.define('HardwareChangeModel', {
	        extend: 'Ext.data.Model',	        
	        fields: [
	            'id', 'parentId','pcName', 'newHwName', 'oldHwName',
	            'reason', 'createStrDate'
	        ],
	        idProperty: 'id'
	    });
		
		var store = Ext.create('Ext.data.Store',{
			model : 'HardwareChangeModel',
			autoLoad: false,
			proxy : {
				type : 'ajax',
				actionMethods : {
					read : 'POST'					
				},
				url : 'hardwareChange/pageList.do',
				reader : {
					type : 'json',
					root : 'list',
	                totalProperty: 'totalCount'
				}
			},
			listeners : {
				scope : this,
				load : function(){
					this.queryById('searchCategory').getStore().reload();
				}
			}
		});
		
		Ext.apply(this,{
			id : 'HardwareChangePanel',
			title : LocaleUtil.getMessage('rms.menu.changeHistory'),
			columns : this.getColumns(),
			store : store,
			selType: 'checkboxmodel',
			viewConfig : Common.viewConfig(true),
			bbar: Common.pagingToolBar(store),
			columnLines: true,
			tbar : [{
				xtype : 'label',
				text : LocaleUtil.getMessage('rms.label.equipment')
			},{
				itemId : 'searchCategory',
				xtype : 'combobox',
				name : 'searchCategory',
				store : [['PC','PC']],
				value : 'PC'
			},{
				itemId : 'searchWordTxt',
				xtype : 'textfield',				
				width : 200,
				enableKeyEvents : true,
				maskRe: Common.getMakeRe(),
				listeners : {
					scope : this,
					keypress : function(txtField, e, eOpts){
						if(e.getKey() == 13){
							this.search();
						}
					}
				}
			},{
				xtype : 'button',
				iconCls : 'detail_search',					
				text : LocaleUtil.getMessage('search'),
				scope : this,
				handler : this.search
			},'->',{
				xtype : 'button',
				text : LocaleUtil.getMessage('reg'),
				iconCls : 'add',
				handler : function(){
					Ext.create('Lms.rms.HardwareChangeInfoDialog').openWindow();
				}
			}]
		});
		this.callParent(arguments);
		this.on('cellclick',this.onCellClickHandler);
		this.on('show',function(){
			store.load();
		},this);
	},
	
	getColumns : function(){
		return [
		    {text : LocaleUtil.getMessage('rms.label.date'),dataIndex : 'createStrDate', width:120},
		    {text : LocaleUtil.getMessage('rms.label.systemName'),dataIndex : 'pcName', width:150},
		    {text : LocaleUtil.getMessage('rms.label.changeReason'),dataIndex : 'reason', flex:1},
		    {text : LocaleUtil.getMessage('rms.label.oldHwName'),dataIndex : 'oldHwName', width:150},
		    {text : LocaleUtil.getMessage('rms.label.newHwName'),dataIndex : 'newHwName', width:150},
	    ];
	},
	
	onCellClickHandler : function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts){
		if(cellIndex == 0) return true;
		if(cellIndex == 1){
			Ext.create('Lms.rms.HardwareChangeInfoDialog').openWindow({id : record.get('id')});
		}
	},
	
	search : function(){
		var searchCategory = this.queryById('searchCategory').getValue();
		var searchWordTxt = this.queryById('searchWordTxt').getValue();
		this.getStore().load({
			params : {
				searchCategory : searchCategory,
				searchWordTxt : searchWordTxt
			}
		});
	}
});